package ai.people.netmon.twitter.view.service.impl;

import ai.people.netmon.framework.domain.twitter.view.entity.TwitterAccountView;
import ai.people.netmon.framework.domain.twitter.view.request.QueryViewRequest;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.twitter.view.mapper.TwitterAccountViewMapper;
import ai.people.netmon.twitter.view.service.TwitterAccountViewService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 说明
 *
 * @author zhenglin
 * @since 2022/3/18
 */
@Service
public class TwitterAccountViewServiceImpl extends ServiceImpl<TwitterAccountViewMapper, TwitterAccountView> implements TwitterAccountViewService {

    @Autowired
    TwitterAccountViewMapper viewMapper;

    @Override
    public PageResponse<TwitterAccountView> listViews(QueryViewRequest request) {
        Page<TwitterAccountView> page = new Page<>(request.getOriginPageNo(),request.getPageSize());
        page.setSearchCount(false);
        IPage<TwitterAccountView> result = viewMapper.listTwitterAccountPage(page,request);
        return PageResponse.builder(result);
    }

    @Override
    public TwitterAccountView getView(String accountName) {
        LambdaQueryWrapper<TwitterAccountView> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(TwitterAccountView::getAccountName,accountName);
        return getOne(queryWrapper);
    }
}
